package com.example.basis.service;

import com.example.basis.model.User;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Service;

/**
 * @version 1.0.0
 * @className: UserService
 * @description: 监听MQ消息
 * @author: LiJunYi
 * @create: 2022/8/4 11:15
 */
@Service
@Slf4j
public class UserService
{
    /**
     * 接收消息
     *
     * @param user 用户
     */
    @RabbitListener(queues = "ajia")
    public void receive(User user){
        log.info("接收到【ajia】队列消息{}",user);
    }

    /**
     * 收到主题信息
     *
     * @param user 用户
     */
    @RabbitListener(queues = "ajia.user")
    public void receiveTopicMsg(User user){
        log.info("交换机【exchange.topic】，接收到【ajia.user】队列消息,{}",user);
    }

    /**
     * 收到扇出信息
     *
     * @param user 用户
     */
    @RabbitListener(queues = "ajia.fanout")
    public void receiveFanoutMsg(User user){
        log.info("交换机【exchange.fanout】，接收到【ajia.fanout】队列消息,{}",user);
    }

    /**
     * 接收消息2
     *
     * @param message 消息
     */
    @RabbitListener(queues = "ajia")
    public void receive02(Message message){
        log.info("接收到【ajia】队列消息方式2,message.getBody:{}",message.getBody());
        log.info("接收到【ajia】队列消息方式2,message.getMessageProperties:{}",message.getMessageProperties());
    }
}
